package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(tags = "套餐管理接口")
@RequestMapping("/admin/setmeal")
@RestController
@Slf4j
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    /**
     * 套餐分页查询
     * @param queryDTO
     * @return
     */
    @ApiOperation("套餐分页查询")
    @GetMapping("/page")
    public Result<PageResult> page(SetmealPageQueryDTO queryDTO){
        PageResult pageResult = setmealService.page(queryDTO);
        return  Result.success(pageResult);
    }


    /**
     * 根据Id查询套餐
     * @param id
     * @return
     */
    @ApiOperation("根据Id查询套餐")
    @GetMapping("/{id}")
    public Result<SetmealVO> getById(@PathVariable Long id){
        //
         SetmealVO setmealVO = setmealService.getById(id);
        return  Result.success(setmealVO);
    }

    /**
     * 新增套餐
     * @param setmealDTO
     * @return
     */
    @CacheEvict(cacheNames = "setmealCatch", key = "#setmealDTO.categoryId")
    @ApiOperation("新增套餐")
    @PostMapping
    public Result save( @RequestBody SetmealDTO setmealDTO){
        setmealService.save(setmealDTO);
        return  Result.success();
    }

    /**
     * 批量删除套餐
     * @return
     */
    @CacheEvict(cacheNames = "setmealCatch")
    @ApiOperation("批量删除套餐")
    @DeleteMapping
    public Result delete(@RequestParam List<Long> ids ){
        setmealService.removeByIds(ids);
        return Result.success();
    }

    /**
     * 修改套餐信息
     * @param setmealDTO
     * @return
     */
    @CacheEvict(cacheNames = "setmealCatch")
    @ApiOperation("修改套餐信息")
    @PutMapping
    public Result update( @RequestBody SetmealDTO setmealDTO ){
        setmealService.updateById(setmealDTO);
        return Result.success();
    }

    /**
     * 更新套餐状态
     * @param status
     * @param id
     * @return
     */
    @CacheEvict(cacheNames = "setmealCatch")
    @ApiOperation("更新套餐状态")
    @PostMapping("/status/{status}")
    public Result updateStatus(@PathVariable Integer status, Long id){
        setmealService.updateStatus(status, id);
        return Result.success();
    }


}
